package com.tiancheng.trade.settlement.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * 业务场景
 *
 * @author kellen
 * @date 2024/3/4
 */
@Getter
@AllArgsConstructor
public enum OrderSourceEnum implements BaseEnum<String> {

    HOTEL("1", "酒店"),
    FLIGHT("2", "机票"),
    TICKET("3", "门票"),
    RESTAURANT("4", "餐饮"),
    UNION_WELFARE("5", "工会福利"),
    ONE_CODE("6","一码通"),
    SHOPPING_MALL("7","商城"),
    PROPERTY("8","物业"),
    CONSOLIDATION("99", "合单"),
    OTHER("100", "其他"),
    ;

    private String code;
    private String desc;

    public static String getDesc(String code) {
        Optional<OrderSourceEnum> found = Arrays.stream(OrderSourceEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (found.isPresent()) {
            return found.get().getDesc();
        }
        return code;
    }

    public static String getSourcesNames(String sourceArr) {
        if (StringUtils.isEmpty(sourceArr)) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (String s : sourceArr.split(",")) {
            sb.append(getDesc(s)).append(",");
        }
        return sb.substring(0, sb.length() - 1);
    }

}
